/* R. J. Cano, Jan 24 2014
 * 
 * Alternative sequencer for A055881.
 * 
 * ( Based upon the comment from Benoit Cloitre on Mar 11 2003 )
 *
*/

/* Determines the number of necessary steps in order to get a(n) */
necessary(n)={my(k=0);while((k+1)!<n,k++);k}

/* Executes the algorithm for k steps */
terms(k)={my(v0=[1],v,u=0,t);if(k<=0,v=v0,while(u++<=k,v=vector((u+1)!);t=v0[#v0]+1;for(i=1,t,for(j=1,#v0,v[(i-1)*#v0+j]=v0[j]));v[#v]++;v0=v));v}

a(n)=if(n>0,terms(necessary(n))[n],-1); /* By -1 we mean "Error" */